package com.hh.bidding.controller;

import com.hh.bidding.domain.BidTenderQuotation;
import com.hh.bidding.service.IBidTenderQuotationService;
import com.hh.bidding.service.business.IBidTenderQuotationServiceBusiness;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 招标报价;(bid_tender_quotation)表控制层
 * @author : http://www.chiner.pro
 * @date : 2025-9-11
 */
@RestController
@RequestMapping("/tenderQuotation")
public class BidTenderQuotationController extends BaseController {
    @Resource
    private IBidTenderQuotationService bidTenderQuotationService;

    @Resource
    private IBidTenderQuotationServiceBusiness bidTenderQuotationServiceBusiness;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @GetMapping("{id}")
    public AjaxResult queryById(@PathVariable("id") Integer id){
        return success(bidTenderQuotationService.queryById(id));
    }

    /**
     * 分页查询
     *
     * @param bidTenderQuotation 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public TableDataInfo paginQuery(BidTenderQuotation bidTenderQuotation){
        startPage();
        List<BidTenderQuotation> list = bidTenderQuotationService.paginQuery(bidTenderQuotation);
        return getDataTable(list);
    }

    /**
     * 获取供应商某个招标项目的所有报价信息
     * @return 返回供应商某个招标项目的所有报价信息
     */
    @GetMapping("/find/{hid}/{sid}")
    public AjaxResult findAllByHidAndSid(@PathVariable("hid") Integer hid,@PathVariable("sid") Integer sid) {
        return AjaxResult.success(bidTenderQuotationService.findAllByHidAndSid(hid,sid));
    }

    /**
     * 获取供应商某个招标项目的最新报价信息
     * @return 返回供应商某个招标项目的最新报价信息
     */
    @GetMapping("/findLast/{hid}/{sid}")
    public AjaxResult findLastQuotationByHidAndSid(@PathVariable("hid") Integer hid,@PathVariable("sid") Integer sid) {
        return AjaxResult.success(bidTenderQuotationServiceBusiness.findLastQuotationByHidAndSid(hid,sid));
    }

    /**
     * 获取供应商某个招标项目的数据库中最新报价信息
     * @return 返回供应商某个招标项目的最新报价信息
     */
    @GetMapping("/findLastInfo/{hid}/{sid}")
    public AjaxResult findLastInfoQuotationByHidAndSid(@PathVariable("hid") Integer hid,@PathVariable("sid") Integer sid) {
        return AjaxResult.success(bidTenderQuotationServiceBusiness.findLastInfoQuotationByHidAndSid(hid,sid));
    }

    /**
     * 返回所有供应商的最新报价信息
     * @param sid
     * @return
     */
    @GetMapping("/findList/{sid}")
    public AjaxResult findAllListBySid(@PathVariable("sid") Integer sid) {
        return AjaxResult.success(bidTenderQuotationServiceBusiness.findAllListBySid(sid));
    }

    /**
     * 新增数据
     *
     * @param bidTenderQuotation 实例对象
     * @return 实例对象
     */
    @PostMapping
    public AjaxResult add(@RequestBody BidTenderQuotation bidTenderQuotation){
        return toAjax(bidTenderQuotationServiceBusiness.biddingPrice(bidTenderQuotation));
    }

    /**
     * 更新数据
     *
     * @param bidTenderQuotation 实例对象
     * @return 实例对象
     */
    @PutMapping
    public AjaxResult edit(@RequestBody BidTenderQuotation bidTenderQuotation){
        return toAjax(bidTenderQuotationService.update(bidTenderQuotation));
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable Integer id){
        return toAjax(bidTenderQuotationService.deleteById(id));
    }
}
